#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i(a);i<=(b);++i)
#define req(i,a,b) for(int i(a);i>=(b);--i)
#define sort stable_sort
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?EOF:*p1++)
template<typename TP> inline TP read(TP &num)
{
	TP x=0;
	int f=0;
	char ch=getchar();
	while(ch<48||ch>57) f|=ch=='-',ch=getchar();
	while(48<=ch&&ch<=57) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return num=f?-x:x;
}
template<typename ...Args> inline void read(Args &...args)
{
	(read(args),...);
}
template<typename TP> inline void write(TP x)
{
	(x<0)?(putchar('-'),x=-x):0;
	(x>9)?(write(x/10),0):0;
	putchar((x%10)^48);
}
template<typename TP> inline void writeln(TP x)
{
	write<TP>(x);
	puts("");
}
int n,k,a[500001],c[500001];
bool operator<(pair<int,int> x,pair<int,int> y){return x.first!=y.first?x.first>y.first:x.second<y.second;}
struct fenwick_tree
{
	vector<pair<int,int>> t;
	fenwick_tree(int n):t(n+1,pair<int,int>{0,1e18}){}
	inline void add(int x,pair<int,int> v){for(;x<(int)t.size();x+=x&-x)t[x]=max(t[x],v);}
	inline pair<int,int> query(int x){pair<int,int> res={0,1e18};for(;x;x-=x&-x)res=max(res,t[x]);return res;}
};
signed main()
{
	freopen("sub.in","r",stdin);
	freopen("sub.out","w",stdout);
	read(n,k);
	vector<int> all;
	rep(i,1,n) read(a[i]),all.push_back(a[i]);
	sort(all.begin(),all.end()),all.erase(unique(all.begin(),all.end()),all.end());
	rep(i,1,n) c[i]=lower_bound(all.begin(),all.end(),a[i])-all.begin()+1;
	int l=0,r=2e9+1,ans=0;
	auto check=[&](int t)->bool
	{
		fenwick_tree T(n+1);
		rep(i,1,n)
		{
			int p=upper_bound(all.begin(),all.end(),t-a[i])-all.begin();
			auto P=p>0?T.query(p):pair<int,int>{0,1e18};
			pair<int,int> cur={1,a[i]};
			if(P.first) cur=max(cur,pair<int,int>{P.first+1,P.second});
			if(cur.first>=k&&cur.second+a[i]<=t)return 1;
			T.add(c[i],cur);
		}
		return 0;
	};
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid)) r=mid-1,ans=mid;
		else l=mid+1;
	}
	writeln(ans);
	return 0;
}
